/**
 * Product.app
 * A MVC application which displays a list of books and their reviews.
 * Uses nested data which is loaded from a single json file.
 */
Ext.Loader.setConfig({
	enabled: true,
	paths   : {
		'Ext.ux' : '../../js/ux',
		'Ext.app' : '../../js/classes',
		'vsg.framework' : '../../js/framework',
		'vsg.security' : '../../js/security',
		'Extensible': '../../js/extensible'
	}			
});
Ext.application({
    name: 'appmod',

    // Define all the controllers that should initialize at boot up of your application
    appFolder :'.',

    controllers: [
        'framework.Viewport',
		'framework.MainMenuPanel'
    ],
    

    launch: function () {
		
		// --- get javascript sid ---
		var scTags = document.getElementsByTagName("script");

		for (var idx = 0 ; idx < scTags.length ; idx++) {
			var scTag = scTags.item(idx);
			if (scTag.src && scTag.src.indexOf('index.js') > 0) {
				// --- get session id ==
				var locIndex = scTag.src.indexOf('sid=');
				var sid = scTag.src.substring(locIndex+4);
				Ext.util.Cookies.set('JSESSIONID',sid);
			}
		}
		
		
		// --- create state provider ---
		Ext.state.Manager.setProvider(new Ext.state.CookieProvider());


		// --- show view ---
		Ext.create('Ext.container.Viewport', {
            layout: 'border',
            items: [{
                collapsible:false,
                xtype : 'panel',
                region : 'north',
                border : false,
                contentEl: 'header'
            },
            {
                region: 'center',
                layout : 'border' ,
                border: false,
                items:[
                {
                    region : 'north',
                    xtype : 'mainmenupanel',
					store:'MenuStore',
                    height : 66,
                    border : false
                },
		        {
		        	region : 'center',
		            xtype:'maincorepanel',
					layout:'fit',
		            border : false,
					id:'main'
		        } 	
                ]
            },
            {
                collapsible:false,
                height : 30,
                border : false,
                xtype : 'panel',
                region : 'south',
                contentEl: 'footer'
            }           
            ]
        });
		
		// --- init and load main core panel ---
		/**
		 * get main core load panel
		 */
		var loadAndStartController = "knowledge.Startup";	
		
		this.loadPanelAndBoot( loadAndStartController );

    },
	
	loadPanelAndBoot :function(controllerName) {
		var me = this;
		
		var corePanels = Ext.ComponentQuery.query('maincorepanel');
		var container = corePanels[0]; 
		
		if (!me.getLaunchController(controllerName)) {
			me.addController(controllerName);
		}
		var controller = this.getController(controllerName);
		if (controller.getDelayforOnLaunch() ) {
			var controllerPanel = controller.loadInitComp();
			container.add(controllerPanel);
						
			// --- start --
			//controller.onLaunch(me);
			//me.launchControllers[controller.id] = 1;				
		}
	
	}
	
	
});



